import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// 路径查找
const pathResolve = (dir: string): string => {
  return resolve(__dirname, '.', dir)
}

const regExps = (value: string, reg: string): string => {
  return value.replace(new RegExp(`^${reg}`, 'g'), '')
}
// 设置别名
const alias: Record<string, string> = {
  '/@': pathResolve('src'),
  '@build': pathResolve('build'),
  '@assets': pathResolve('assets'),
}
export default defineConfig({
  plugins: [vue()],
  // 服务端渲染
  server: {
    open: true,
    // 是否开启 https
    https: false,
    // 端口号
    port: 8080,
    host: '127.0.0.1',
    // 本地跨域代理
    // 代理相关配置，开发联调打开,
    // proxy: {
    //   '/tag': {
    //     target: 'http://47.110.69.221/api',
    //     ws: true,
    //     secure: false,
    //     changeOrigin: true,
    //     rewrite: (path: string) => regExps(path, '/tag'),
    //     // pathRewrite:(path:string) {
    //     //   '^/tag': '/',
    //     // },
    //   },
    // },
  },
})
